<?
if($_SESSION[ "authority"]!="admin" && false){
   include "../NIV/checkauthority.php"; 
}else{
$group=isset($_REQUEST["groupby"])?$_REQUEST["groupby"]:"''";

switch ($group){
    case "Name":
        $groupby="LEFT(`name`,1)";
        break;
    case "Type":
        $groupby="`type`";
        break;
    default :
        $groupby="''";
}
if($_REQUEST["type"]=="trash")
    $nivOrdata=$TemplateModule->getTemplates_Trash($groupby);
elseif($_REQUEST["type"]=="public")
    $nivOrdata=$TemplateModule->getTemplates_Public($groupby);
elseif($_REQUEST["type"]=="private")
    $nivOrdata=$TemplateModule->getTemplates_Private($groupby);
else
    $nivOrdata=$TemplateModule->getTemplates($groupby);
?>
<table class="table-data" style="width: 960px;margin-top: 0px">
    <tr>
        <th>No.</th>
        <th>ID</th>
        <th style="min-width: 180px">
            <img style="float: left;  padding-right: 4px;<?=$group!="Name"?"opacity: 0.25;cursor: pointer;":""?>" src="images/icon/stock_group_cells.png"
                 title="Group by Name"
                 onclick="organ_all_groupby('<?=$_REQUEST["type"]?>','Name');"
                 />
            Name
        </th>
        <th>Status</th>
        <th  style="width: 120px">
            <img style="float: left;padding-right: 4px;<?=$group!="Type"?"opacity: 0.25;cursor: pointer;":""?>" src="images/icon/stock_group_cells.png"
                 title="Group by Type"
                 onclick="organ_all_groupby('<?=$_REQUEST["type"]?>','Type');"
                 />
            Type
        </th>
        <th style="width: 120px">
            Insert
        </th>
        <th style="width: 120px">
            Update
        </th>
        <th style="min-width: 120px">#</th>
    </tr>
    <tr class="id-head-row inew<?=$_REQUEST["type"]?>">
        <td colspan="8">
            <div class="new" style=""
                 onclick="show_item('','inew<?=$_REQUEST["type"]?>');"
                 >
                ++New
            </div>
            
        </td>
    </tr>
    <tr class="id-content-row inew<?=$_REQUEST["type"]?> hidden">
        <td colspan="8">
            <center>đang tải...<br/>
                Nếu trang không tự tải nội dung hãy ấn vào 
                <a class="loadding" href="javascript:show_item('<?=$r["id"]?>','<?=$_REQUEST["type"]?>');">đây</a> để tải lại.<br/>
                Hoặc ấn vào <a href="02_Admin_planners.php?Unit=template_detail&id=<?=$r["id"]?>">đây</a> để tải tại tab khác.
            </center>
        </td>
    </tr>

<?
//organization
$n=0;
$gr="";
if($nivOrdata==null){
    echo "<tr><td colspan='8' style='text-align:center'>No data to display</td></tr>";
}else foreach ($nivOrdata as $r){
    $n++;
    if(strtolower(str_replace(" ", "", $gr))!=strtolower(str_replace(" ", "",$r["group"]))){
        $gr=$r["group"];
        echo "<tr style='background:#D7D7D7'><td colspan='8' ><b>".$group." : ".$r["group"]."</b></td></tr>";
    }
    if(!$r["status"])$status="Private";
    else $status=$r["status"];
?>
    <tr class="id-head-row <?=$_REQUEST["type"]?><?=$r["id"]?> <?=$r["delete"]?"cred":($r["status"]!="Private"?"cblue":"")?>">
        <td><?=$n?></td>
        <td><?=$r["id"]?></td>
        <td><?=$r["name"]?></td>
        <td><?=$status?></td>
        <td><?=$r["type"]?></td>
        <td><?=$r["insert"]?></td>
        <td><?=$r["update"]?></td>
        <td style="padding: 0;margin: 0;vertical-align: middle">
            
            
                <?
                if($_REQUEST["type"]=="trash"){
                    ?>
                <div class="icon16 hover50 tooltip" title="Restore"
                     onclick="restoretemplate('<?=$r["id"]?>');"
                     >
                    
                    <img src="./images/icon/gtk_undelete.png">
                </div>
                    <?
                }else{
                ?>
                <span class="action" style="margin-top: 3px">
                <div class="icon16 hover50 tooltip"
                        title="Delete"
                        onclick="deletetemplate('<?=$r["id"]?>');"
                        >
                    <img src="./images/icon/16/edit_delete.png">
                </div>
                <div class="icon16 hover50 tooltip"
                        title="Edit"
                        onclick="show_item('<?=$r["id"]?>','<?=$_REQUEST["type"]?>');"
                        >
                    <img src="./images/icon/16/document_edit.png">
                </div>
                <div class="icon16 hover50 tooltip"
                        title="Album"
                        >
                    <img src="./images/icon/16/stock_slide_show.png">
                </div>
                </span>
                <?
                }
                ?>
            
        </td>
    </tr>
    <tr class="id-content-row <?=$_REQUEST["type"]?><?=$r["id"]?> hidden">
        <td colspan="8">
            <center>đang tải...<br/>
                Nếu trang không tự tải nội dung hãy ấn vào 
                <a class="loadding" href="javascript:show_item('<?=$r["id"]?>','<?=$_REQUEST["type"]?>');">đây</a> để tải lại.<br/>
                Hoặc ấn vào <a href="02_Admin_planners.php?Unit=template_detail&id=<?=$r["id"]?>">đây</a> để tải tại tab khác.
            </center>
        </td>
    </tr>
<?
}
?>
</table>
<?
}
?>
<div class="clear"></div>
<script>
    $('.tooltip').poshytip({
        className: 'tip-yellowsimple',
        hideTimeout:0,
        alignTo: 'target',
        alignX: 'center',
        allowTipHover: false,
        hideAniDuration:0
    });
</script>